package work5;

/**
 * @TODO
 * @Author xu
 * 2025/2/26
 */
public class JiuGongGe {
    public static void main(StringTest[] args) {
        int n = 5;
        int[][] magicSquare = new int[n][n];

        int row = 0;
        int col = n / 2;

        for (int num = 1; num <= n * n; num++) {
            magicSquare[row][col] = num;
            row--;
            col++;

            if (num % n == 0) {
                row += 2;
                col--;
            } else {
                if (col == n) col -= n;
                if (row < 0) row += n;
            }
        }

        for (int[] r : magicSquare) {
            for (int value : r) {
                System.out.printf("%2d ", value);
            }
            System.out.println();
        }
    }

}
